package com.neuedu.service.Imp;

import cn.hutool.core.util.StrUtil;
import com.neuedu.dao.FoodDao;
import com.neuedu.dao.Imp.FoodDaoImp;
import com.neuedu.pojo.Food;
import com.neuedu.pojo.PageResult;
import com.neuedu.service.FoodService;

import java.util.List;

public class FoodServiceImp implements FoodService {
    private FoodDao foodDao = new FoodDaoImp();

    @Override
    public PageResult<List<Food>> getFood(String currentPage, String pageSize, String foodName, String categoryId, String shopId) {
        try{
            /*Integer page = 0;
            Integer size = 0;
            if(StrUtil.isNotBlank(currentPage)){
                page = Integer.valueOf(currentPage);
            }
            if(StrUtil.isNotBlank(pageSize)){
                page = Integer.valueOf(pageSize);
            }
            page = (page - 1) * size;*/
            List<Food> food = foodDao.getFood(currentPage, pageSize, foodName, categoryId, shopId);
            Long l = foodDao.countFood(shopId);
            PageResult<List<Food>> pageResult = new PageResult<>();
            pageResult.setDatas(food);
            pageResult.setTotal(l);
            return pageResult;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer addFood(String foodName, String foodExplain, String foodImg, String foodPrice, String shopId, String remarks, String stock, String status, String categoryId, String recommend, String hot) {
        try{
            /*Food food = new Food();
            food.setFoodName(foodName);
            food.setFoodExplain(foodExplain);
            food.setFoodImg(foodImg);
            food.setFoodPrice(Double.parseDouble(foodPrice));
            food.setShopId(Integer.parseInt(shopId));
            food.setRemarks(remarks);
            food.setStock(Integer.valueOf(stock));
            food.setStatus(Integer.parseInt(status));
            food.setCategoryId(Integer.parseInt(categoryId));
            food.setRecommend(Integer.parseInt(recommend));
            food.setHot(Integer.parseInt(hot));
            return foodDao.addFood(food);*/
            return foodDao.addFood(foodName,foodExplain,foodImg,foodPrice,shopId,remarks,stock,status,categoryId,recommend,hot);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer updateFood(String foodName, String foodExplain, String foodImg, String foodPrice, String remarks, String stock, String status, String categoryId, String foodId) {
        try{
            /*Food food = new Food();
            food.setFoodName(foodName);
            food.setFoodExplain(foodExplain);
            food.setFoodImg(foodImg);
            food.setFoodPrice(Double.parseDouble(foodPrice));
            food.setRemarks(remarks);
            food.setStock(Integer.valueOf(stock));
            food.setStatus(Integer.parseInt(status));
            food.setCategoryId(Integer.parseInt(categoryId));
            food.setFoodId(Integer.valueOf(foodId));
            return foodDao.updateFood(food);*/
            return foodDao.updateFood(foodName,foodExplain,foodImg,foodPrice,remarks,stock,status,categoryId,foodId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Integer delFood(String foodId) {
        try{
            return foodDao.delFood(foodId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
